package com.corn.juc.util;

import lombok.SneakyThrows;

import java.util.concurrent.CyclicBarrier;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2020/12/30 16:08
 */

public class CyclicBarrierDemo {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> {
            System.out.println("七龙珠集齐召唤神龙");
        });

        for (int i = 1; i < 8; i++) {
            int finalI = i;
            new Thread() {
                @SneakyThrows
                @Override
                public void run() {
                    System.out.println(String.format("找到第%s龙珠", String.valueOf(finalI)));
                    cyclicBarrier.await();
                }
            }.start();
        }
    }
}
